﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using edu.Model;

namespace edu.Web
{
    public static class Pad
    {

        /// <summary>
        /// 生成许愿贴的HTML代码
        /// </summary>
        /// <param name="screenWidth">用户屏幕的宽度</param>
        /// <param name="screenHeight">用户屏幕的高度</param>
        /// <returns></returns>
        public static string ToHtml(int screenWidth, int screenHeight)
        {
            StringBuilder wallHTML = new StringBuilder();
            Random rnd = new Random();
            int zIndex = 1;
            List<Wish> wish = new List<Wish>();
            wish.Add(new Wish() { FromUser = "张三", Message = "你们的网站不错哦", CreateDate = DateTime.Now, StyleIdx = 1, ImageIdx = 15 });
            wish.Add(new Wish() { FromUser = "张三", Message = "你们的网站不错哦", CreateDate = DateTime.Now, StyleIdx = 2, ImageIdx = 15 });
            wish.Add(new Wish() { FromUser = "张三", Message = "你们的网站不错哦", CreateDate = DateTime.Now, StyleIdx = 3, ImageIdx =15});
            wish.Add(new Wish() { FromUser = "张三", Message = "你们的网站不错哦", CreateDate = DateTime.Now, StyleIdx = 4, ImageIdx = 15 });
            wish.Add(new Wish() { FromUser = "张三", Message = "你们的网站不错哦", CreateDate = DateTime.Now, StyleIdx = 5, ImageIdx = 15 });
            foreach(Wish w in wish)
            {
                wallHTML.AppendFormat(AppConfig.PadTemplate,
                    zIndex,
                    rnd.Next(AppConfig.WallLeftLimit, screenWidth),
                    rnd.Next(AppConfig.WallTopLimit, screenHeight),
                    w.StyleIdx,
                    w.CreateDate,
                    w.Message,
                    w.ImageIdx,
                    w.FromUser);
                wallHTML.AppendLine();
                zIndex++;
            }

            return wallHTML.ToString();
        }

        /// <summary>
        /// 字符串过滤
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        private static string ApplyFilter(string parameter)
        {
            parameter = System.Web.HttpUtility.HtmlEncode(parameter);
            return parameter.Replace('-', '－').Replace("'", "''").Replace(';', '；')
                .Replace('(', '（').Replace(')', '）').Replace('\\', '|');
        }
    }
}